
package samples;
// {{{ imports
import jp.ize.ux.UXRoot;
import jp.ize.ux.UXObject;
import jp.ize.ux.events.UXMouseEvent;
import jp.ize.ux.geom.UXSize;
import jp.ize.ux.geom.UXRect;
import jp.ize.ux.geom.UXPoint;
import jp.ize.ux.components.UXImage;
import jp.ize.ux.components.UXLinearBox;
import jp.ize.ux.acts.Act;
import jp.ize.ux.acts.LinearAct;
import jp.ize.ux.tween.easings.Expo;

import jp.ize.iwp.RuntimeEngine;
import jp.ize.iwp.utils.DebugUtil;
// }}}
// {{{ class LinearBox4
class LinearBox4
{
	// {{{ public static function main()

	public static function main()
	{
		RuntimeEngine.init();
		DebugUtil.init();
		DebugUtil.setLocation( 300, 100 );
		// {{{ ex.4 wipe & layout
		var lineb = new UXLinearBox(new UXPoint(100,150), new UXPoint(700,150));
		// LayoutのインタラクションをMouseDownで起こすことにする。
		lineb.ctrl.getInteraction("Layout").addReactEvent(UXMouseEvent.DOWN);
		lineb.x = 100;
		lineb.y = 200;
		lineb.addUXChild(new UXImage("Pref.png"));
		lineb.addUXChild(new UXImage("Safari.png"));
		lineb.addUXChild(new UXImage("TimeMachine.png"));
		lineb.addUXChild(new UXImage("iPhoto.png"));
		lineb.addUXChild(new UXImage("iTunes.png"));
		lineb.addUXChild(new UXImage("mail.png"));
		UXRoot.addUXChild(lineb);
		var a = new LinearAct();
		// {{{ wipe action
		// 最初のレイアウト終了後は、wipeインタラクションと整列インタラクションを
		// 交互に発生させるようにします。
		var acts1:Array<UXLinearBoxState->Void> = 
					lineb.ctrl.getInteraction("Layout").getActs();
		var acts2:Array<UXLinearBoxState->Void> = new Array();

		var func:LinearMovable->WipeParameter = function(state) {
			var idx:Int = 0;
			for ( i in 0...state.children.length ) {
				if ( state.children[i]==state.eventTarget ) {
					idx = i;
				}
			}
			var actparam:WipeParameter = {
				time:0.3,
				transition:Expo.easeOut,
				center:idx
			};
			return actparam;
		}

		acts2.push(a.wipe(null,func));

		var flag:Bool = false;
		lineb.ctrl.getInteraction("Layout").addFinishHandler(
			function(state) {
				if ( flag ) {
					lineb.ctrl.getInteraction("Layout").setActs(acts1);
					flag = false;
				} else {
					lineb.ctrl.getInteraction("Layout").setActs(acts2);
					flag = true;
				}
			}
		);
		// }}}
		lineb.ctrl.trigger("Layout");
		// }}}
	}

	// }}}
}
// }}}
